<?php
    /* 
    *接口说明:  订餐统计信息上传
    *创建者: 	kai
    *时间:	  	20180319
    */
    //echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
    require_once 'commom/dbfunction.php';
    require_once 'commom/config.php';

    $arrResult = null;
    $conn = null;
    $json_infoString = isset($_GET['info']) ? $_GET['info'] : '';

    do
    {
        // 检查传入参数是否为空
        if(empty($json_infoString)){
            $arrResult = array(
            "errcode" => 1,
            "info" => "get参数为空",
            );
            break;
        }

        // 检查几个重要参数是否为空
        $json_info = json_decode($json_infoString, true);
        // 获取信息
        $shareuniqueid = "";
        $sharedate = "";
        $publisheropenid = "";
        $publishername = "";
        $publishericon = "";
        $enddate = "";
        $endtime = "";
        $split = "";
        $orderexplain = "";
        $formid = "";
        $R1 = 0; 
        $R2 = 0;
        $R3 = 0;
        $R4 = "";
        $R5 = "";
		if(isset($json_info['shareuniqueid']) && !empty($json_info['shareuniqueid'])){
			$shareuniqueid = $json_info['shareuniqueid'];
        }else{
            $arrResult = array(
                "errcode" => 2,
                "info" => "shareuniqueid无效",
                );
            break;
        }
        if(isset($json_info['sharedate'])){
			$sharedate = $json_info['sharedate'];
        }
        if(isset($json_info['publisheropenid']) && !empty($json_info['publisheropenid'])){
			$publisheropenid = $json_info['publisheropenid'];
        }else{
            $arrResult = array(
                "errcode" => 2,
                "info" => "publisheropenid无效",
                );
            break;
        }
        if(isset($json_info['publishername'])){
			$publishername = $json_info['publishername'];
        }
        if(isset($json_info['publishericon'])){
			$publishericon = $json_info['publishericon'];
        }
        if(isset($json_info['enddate'])){
			$enddate = $json_info['enddate'];
        }
        if(isset($json_info['endtime'])){
			$endtime = $json_info['endtime'];
        }
        if(isset($json_info['split'])){
			$split = $json_info['split'];
        }
        if(isset($json_info['orderexplain'])){
			$orderexplain = $json_info['orderexplain'];
        }
        if(isset($json_info['formid'])){
			$formid = $json_info['formid'];
        }
        
        // 插入到数据库中
        $sql = "INSERT INTO orderstat (shareuniqueid, sharedate, publisheropenid, publishername, publishericon, enddate, endtime, split, orderexplain, formid, R1, R2, R3, R4, R5)
                        values('".$shareuniqueid."','".$sharedate."','".$publisheropenid."','".$publishername."','".$publishericon."','".$enddate."','".$endtime."','".$split."','".$orderexplain."','".$formid."',".$R1.",".$R2.",".$R3.",'".$R4."','".$R5."')";
        $conn = my_connect(DB_HOST, DB_USER, DB_PWD, DB_CHARSET, DB_DBNAME);
        // 执行数据库操作
        if(!mysqli_query($conn, $sql)){
            $arrResult = array(
                "errcode" => 3,
                "info" => "数据库插入失败，error=".mysqli_error($conn),
                );
            break;
        }
        
        // 成功
		$arrResult = array(
					"errcode" => 0,
					"info" => $sql,
					);
    }while(false);

    // 关闭数据库链接
    if($conn){
        my_close($conn);
    }
    // 输出结果
    echo json_encode($arrResult);
?>